package com.ykt.vo;

import com.jfinal.kit.JsonKit;

/**
 * 返回结果
 *
 * @author long.hua
 * @version 1.0.0
 * @since 2015-12-08 23:01
 */
public class ResultVo<V> {

    private V data; // 返回的VO对象
    private int code;
    private String message;

    public ResultVo(int code, String message){
        this.code = code;
        this.message = message;
    }

    public ResultVo(V v, int code, String message){
        this.data = v;
        this.code = code;
        this.message = message;
    }

    public static <V> ResultVo success(V data){
        return new ResultVo<>(data, ErrorCode.SUCCESS, ErrorCode.SUCCESS_MSG);
    }

    public static <V> ResultVo failure(V data){
        return new ResultVo<>(data, ErrorCode.FAILURE, ErrorCode.FAILURE_MSG);
    }

    public V getData() {
        return data;
    }

    public void setData(V data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    @Override
    public String toString() {
        return JsonKit.toJson(this);
    }

    public static void main(String[] args) {
        UserVo vo=new UserVo();

        ResultVo rvo = ResultVo.success(vo);
        System.out.println(rvo);
    }
}
